from django.db import models

# Create your models here.
from assistinfo.models import *
from common.constant import *


class BasementManager(models.Model):
    basenum = models.CharField(verbose_name='仓库编号', max_length=255, unique=True)
    name = models.CharField(verbose_name='仓库名称', max_length=255, unique=True)
    status = models.CharField(verbose_name='状态', max_length=2, choices=ENABLE_STATUS, default='1')
    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = verbose_name = '仓库'


class PeopleManager(models.Model):
    STATUS = (
        ('0', '已禁用'),
        ('1', '已启用')
    )

    peoplenum = models.CharField(verbose_name='职员编号', max_length=255, unique=True)
    name = models.CharField(verbose_name='职员名称', max_length=255, unique=True)
    status = models.CharField(verbose_name='状态', max_length=2, choices=STATUS, default='1')

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = verbose_name = '职员'


class AccountManager(models.Model):
    ACCOUNT_TYPE = (
        ('0', '现金'),
        ('1', '银行存款')
    )

    account_num = models.CharField(verbose_name='账户编号', unique=True, max_length=255)
    account_name = models.CharField(verbose_name='账户名称', unique=True, max_length=255)
    balance_date = models.DateField(verbose_name='余额日期')
    balanse_money = models.DecimalField(verbose_name='期初余额', default=0, max_length=200, max_digits=200,
                                        decimal_places=2)
    account_type = models.CharField(verbose_name='账户类型', choices=ACCOUNT_TYPE, max_length=2, default='0')
    is_default = models.BooleanField(verbose_name='是否默认', default=False)

    def __str__(self):
        return self.account_name

    class Meta:
        verbose_name_plural = verbose_name = '结算账户'


class Supplier(models.Model):
    supplier_num = models.CharField(verbose_name='供应商编号', max_length=255, unique=True)
    supplier_name = models.CharField(verbose_name='供应商编号', max_length=255, unique=True)
    supplier_catagery = models.ForeignKey(SupplierCatagery, verbose_name='供应商类别')
    balance_date = models.DateField(verbose_name='余额日期')
    balanse_money = models.DecimalField(verbose_name='期初预付款', default=0, max_length=200, max_digits=200,
                                        decimal_places=2)
    tax_percentange = models.DecimalField(verbose_name='增值税税率', default=0, max_length=200, max_digits=200,
                                          decimal_places=2)
    comment = models.TextField(verbose_name='备注', max_length=4000)

    def __str__(self):
        return self.supplier_name

    class Meta:
        verbose_name_plural = verbose_name = '供应商'


class SupplierConcator(models.Model):
    IS_FIRST_PEOPLE = (
        ('0', '否'),
        ('1', '是')
    )
    name = models.CharField(verbose_name='联系人', max_length=255, unique=True)
    phone = models.CharField(verbose_name='手机', max_length=255)
    tel = models.CharField(verbose_name='座机', max_length=255)
    qq = models.CharField(verbose_name='QQ', max_length=255)
    address = models.CharField(verbose_name='联系地址', max_length=255)
    is_first_people = models.CharField(verbose_name='首要联系人', max_length=2, default='0', choices=IS_FIRST_PEOPLE)
    supplier = models.ForeignKey(Supplier, verbose_name='联系人')

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = verbose_name = '供应商联系人'


class Customer(models.Model):
    customer_num = models.CharField(verbose_name='客户编号', max_length=255, unique=True)
    customer_name = models.CharField(verbose_name='客户名称', max_length=255, unique=True)
    customer_catagery = models.ForeignKey(CustomCatagery, verbose_name='客户类别')
    customer_level = models.ForeignKey(CustomLevel, verbose_name='客户等级')

    balance_date = models.DateField(verbose_name='余额日期')
    balanse_money = models.DecimalField(verbose_name='期初应付款', default=0, max_length=200, max_digits=200,
                                        decimal_places=2)
    balanse_pre_money = models.DecimalField(verbose_name='期初预收款', default=0, max_length=200, max_digits=200,
                                            decimal_places=2)
    comment = models.TextField(verbose_name='备注', max_length=4000)

    def __str__(self):
        return self.customer_name

    class Meta:
        verbose_name_plural = verbose_name = '客户'


class CustomerConcator(models.Model):
    IS_FIRST_PEOPLE = (
        ('0', '否'),
        ('1', '是')
    )
    name = models.CharField(verbose_name='联系人', max_length=255, unique=True)
    phone = models.CharField(verbose_name='手机', max_length=255)
    tel = models.CharField(verbose_name='座机', max_length=255)
    qq = models.CharField(verbose_name='QQ', max_length=255)
    address = models.CharField(verbose_name='联系地址', max_length=255)
    is_first_people = models.CharField(verbose_name='首要联系人', max_length=2, default='0', choices=IS_FIRST_PEOPLE)
    supplier = models.ForeignKey(Customer, verbose_name='联系人')

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = verbose_name = '客户联系人'


class Product(models.Model):
    product_num = models.CharField(verbose_name='商品编号', max_length=255, unique=True)
    product_name = models.CharField(verbose_name='商品名称', max_length=255, unique=True)
    product_sn = models.CharField(verbose_name='商品条码', max_length=255)
    product_spec = models.CharField(verbose_name='规格型号', max_length=255)
    product_kind = models.ForeignKey(CommodityCatagery, verbose_name='商品类别')
    basement = models.ForeignKey(BasementManager, verbose_name='首选仓库')
    unit = models.ForeignKey(CountUnit, verbose_name='计量单位')
    retail_price = models.DecimalField(verbose_name='零售价', default=0, max_length=200, max_digits=200,
                                       decimal_places=2)
    batch_price = models.DecimalField(verbose_name='批发价', default=0, max_length=200, max_digits=200,
                                      decimal_places=2)
    vip_price = models.DecimalField(verbose_name='VIP会员价', default=0, max_length=200, max_digits=200,
                                    decimal_places=2)
    discount_pect_1 = models.DecimalField(verbose_name='折扣率一', default=0, max_length=200, max_digits=200,
                                          decimal_places=2)
    discount_pect_2 = models.DecimalField(verbose_name='折扣率二', default=0, max_length=200, max_digits=200,
                                          decimal_places=2)
    preby_price = models.DecimalField(verbose_name='预计采购价', default=0, max_length=200, max_digits=200,
                                      decimal_places=2)
    comment = models.TextField(verbose_name='备注', max_length=4000)
    has_base_alert = models.BooleanField(verbose_name='库存预警')
    lower_alert = models.IntegerField(verbose_name='最低库存', blank=True, null=True)
    upper_alert = models.IntegerField(verbose_name='最高库存', blank=True, null=True)

    def __str__(self):
        return self.product_name

    class Meta:
        verbose_name_plural = verbose_name = '商品'


class ProductPic(models.Model):
    pic = models.ImageField(verbose_name='商品图片')
    product = models.ForeignKey(Product, verbose_name='商品')

    class Meta:
        verbose_name_plural = verbose_name = '商品图片'
